package main

import (
	"fmt"
	"net"
	"sync"
	"time"
)

func main() {
	serverAddr := "192.168.71.25:8000" // 替换为你的服务端地址
	concurrency := 128                 // 并发连接数
	connectionTimeout := 10 * time.Second

	var wg sync.WaitGroup
	wg.Add(concurrency)

	for i := 0; i < concurrency; i++ {
		go func(i int) {
			defer wg.Done()
			conn, err := net.DialTimeout("tcp", serverAddr, connectionTimeout)
			if err != nil {
				fmt.Printf("连接失败: %v,%v,\n", err, i)
				return
			}
			defer conn.Close()

			fmt.Printf("连接成功: %d\n", i)
			// 保持连接活跃，模拟不调用 Accept()
			conn.Write([]byte("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"))
			buf := make([]byte, 1024)
			conn.Read(buf) // 读取响应

			fmt.Printf("连接 %d 完成数据交互\n", i)
			time.Sleep(100 * time.Second)
		}(i)
	}

	wg.Wait()
}
